package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCollectMapper;
import com.qf.pojo.DtsCollect;
import com.qf.service.DtsCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author bss
 * @version V1.0
 * @Project maven
 * @Package com.qf.service.impl
 * @Description:
 * @Date 2022/10/16 20:51
 */
@Service
public class DtsCollectServiceImpl implements DtsCollectService {

    @Autowired
    DtsCollectMapper collectMapper;
    @Override
    public Map<String, Object> selectByPage(Integer page, Integer limit, String sort, String order, Integer valueId, Integer userId) {
        IPage<DtsCollect> iPage = new Page<>(page,limit);
        LambdaQueryWrapper<DtsCollect> wrapper = new LambdaQueryWrapper<>();

        if (userId!=null){
            wrapper.like(DtsCollect::getUserId,userId);
        }
        if (valueId!=null){
            wrapper.like(DtsCollect::getValueId,valueId);
        }

        if ("desc".equalsIgnoreCase(order)){
            wrapper.orderByDesc();
        }else {
            wrapper.orderByAsc();
        }


         iPage = collectMapper.selectPage(iPage, wrapper);
        Map<String, Object> data = new HashMap<>();
        data.put("total", iPage.getTotal());
        data.put("items", iPage.getRecords());
        return data;
    }
}
